<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<style>
    .btn {
        position: absolute;
        top: 30%;
        left: 30%;
        background: red;
        color: #FFFFFF;
        text-align: center;
        line-height: 50px;
        width: 200px;
        height: 50px;
        border-radius: 10px;
        cursor: pointer;
    }
</style>
<body>
<div class="btn" onclick="handleClick()">
    点击
</div>
</body>
</html>
<script>
    let isExecuting = false;
    let seconds = 0

    function executeOnceInFiveSeconds() {
        if (isExecuting && seconds) {
            console.log('函数正在执行中，请稍后再试。');
            return false
        }
        isExecuting = true;
        seconds = getRandomNumber(10, 30)
        // 函数体
        getLog()
        const timeout = setTimeout(() => {
            // 执行完毕后，重置标志位
            isExecuting = false;
            // 置零
            seconds = 0
            // 清除定时器
            clearTimeout(timeout)
        }, seconds);
    }

    function getLog() {
        console.log('HELLO WORD')
    }

    function handleClick() {
        executeOnceInFiveSeconds()
    }

    // 获取随机整数
    function getRandomNumber(min, max) {
        const seconds = (Math.floor(Math.random() * (max - min + 1)) + min)
        console.log(`${seconds}秒后执行`)
        return seconds * 1000;
    }

</script>
